package cn.yuxiaoyuan.controller;

import cn.yuxiaoyuan.common.util.R;
import cn.yuxiaoyuan.service.IMenuService;
import cn.yuxiaoyuan.service.IPermissionService;
import cn.yuxiaoyuan.system.domain.Menu;
import cn.yuxiaoyuan.system.domain.Permission;
import cn.yuxiaoyuan.system.query.MenuQuery;
import cn.yuxiaoyuan.system.query.PermissionQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author solargen
 * @version 1.0
 * @date 2025/5/19 9:51
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;
    @GetMapping("/{id}")
    public R findById(@PathVariable("id")Long id){
        return R.ok(menuService.findById(id));
    }

    @ApiOperation(value = "查询全部用户信息")
    @GetMapping
    public R findAll(){
        return R.ok(menuService.findAll());
    }

    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id")Long id){
        menuService.deleteById(id);
        return R.ok();
    }
    @PostMapping("/deleteAll")
    public R batchDelete(@RequestBody List<Long> ids){
        menuService.batchDelete(ids);
        return R.ok();
    }

    @PostMapping
    public R add(@RequestBody Menu menu){
        if(menu.getId() == null){
            menuService.add(menu);
        }else {
            menuService.update(menu);
        }
        return R.ok();
    }

    @PostMapping("/list")
    public R pageList(@RequestBody MenuQuery menuQuery){
        return menuService.pageList(menuQuery);
    }
    @GetMapping("/getTree")
    public R getTree(){
        return menuService.getTree();
    }
}
